//testing svn
package com.bluesky.light2.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.bluesky.light2.model.User;
import com.bluesky.light2.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

@Component("userAction")
@Scope("prototype")
public class UserAction extends ActionSupport {
	
	private List<User> users;
	private User user;
	private UserService userService;
	private int id;
	private String oldPassword;
	private String password;
	private String password2;
	
	public String addInput() {
		return INPUT;
	}
	
	public String infoModifyInput() {
		user = userService.loadById(id);
		return INPUT;
	}
	
	public String infoModify() {
		userService.updateInfo(user);
		return SUCCESS;
	}	
	
	public String passwordModifyInput() {
		user = userService.loadById(id);
		return INPUT;
	}
	
	public String passwordModify() {
		user.setPassword(password);
		userService.updatePassword(user);
		return SUCCESS;
	}
	
	public String add() {
		userService.add(user);
		return SUCCESS;
	}
	
	public String list() {
		users = userService.getUsers();
		return SUCCESS;
	}
	
	public String delete() {
		userService.deleteById(id);
		return SUCCESS;
	}

	public String login() {
		user = userService.loadByUsername(user.getUsername());
		if (user != null && password != null && user.getPassword().equals(password)) {
			return LOGIN;
		}
		return ERROR;
	}
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public UserService getUserService() {
		return userService;
	}

	@Resource
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPassword2() {
		return password2;
	}

	public void setPassword2(String password2) {
		this.password2 = password2;
	}

	public String getOldPassword() {
		return oldPassword;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}
}
